package hmvictor.jpql;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.filesystems.FileChooserBuilder;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;

@ActionID(
        category = "File",
        id = "hmvictor.jpql.SaveAsAction"
)
@ActionRegistration(
        displayName = "#CTL_SaveAsAction"
)
@ActionReference(path = "Menu/File", position = 1300)
@Messages("CTL_SaveAsAction=Save As")
public final class SaveAsAction implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        JPQLEditorTopComponent c = (JPQLEditorTopComponent) WindowManager.getDefault().findTopComponent("JQPLEditorTopComponent");
        File home = new File(System.getProperty("user.home"));
        File file = new FileChooserBuilder("user-dir").setTitle("Save File").setDefaultWorkingDirectory(home).setApproveText("Save").showSaveDialog();
        if(file != null) {
            c.saveContent(file);
        }
    }
}
